import os
import zipfile
import easygui as g
import sys

g.msgbox('                          欢迎使用自动分类压缩工具\n   \n                                  请选择目录')


b = g.diropenbox()
#b=r'C:\py\20200730'
print(b)
script_path=os.path.abspath(sys.argv[0])
os.chdir(b)
#后缀排除清单
exclude_list=['zip','py','gpg','gpg','bat','exe']

#筛选符合条件的文件， 去掉子文件夹， 去掉排除列表
def ok_to_zip(filename):
    if filename.split('.')[-1] in exclude_list:
        return False
    elif '.' not in filename:
        return False
    else:
        #print(n,n.split('.')[-1])
        
        return True

def first_filename(filename):
    return filename.split('.')[0]
    

    
filelist=os.listdir(b)
toziplist = list(filter(ok_to_zip, filelist))

print('ok to zip list',toziplist)


#namelist=set(map(first_filename,toziplist))
#print('namelist:',namelist)

def zipfile1(file):

    with zipfile.ZipFile(first_filename(file)+'.zip', 'a') as myzip:
        myzip.write(file)


for file in toziplist:
    zipfile1(file)
print(0,__file__)
print(1,os.path.abspath(sys.argv[0]))
print(2,os.path.dirname(__file__))
pgpexe=os.path.dirname(script_path)+'\\gpg_cmd.cmd'
print(3,'pgpexe:',pgpexe)

os.system(pgpexe)
    

os.startfile(b)

g.msgbox('已完成压缩，请查看')

